<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="../frame/header.jsp"></jsp:include>

<title>共享资料管理</title>
<style>
.checkbox {
	padding-left: 0px;
}

div.in-line {
	margin-top: 5px;
}

div.in-line label {
	width: 70px;
	text-align: right;
}

#searchBtn {
	text-align: right;
}

.form-horizontal .form-actions {
	padding-left: 0px;
}
</style>
</head>

<body>

	<div class="container-fluid">
		<div id="market" class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">学术讨论</a> <span class="divider">/</span></li>
					<li><a href="#">共享资料</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-th"></i> 共享文件列表
					</h2>

					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<div id="search-form">
						<form id="searchForm" method="post" class="form-search span12"
							action="<c:url value="/admin/study/search_attach"/>">
							<div class="in-line">
								<label>院系专业：</label> <select data-placeholder="全部" id="sorts_0"
									name="sortId" data-rel="chosen">
									<option value="0">全部</option>

								</select> <label>学习小组：</label> <select data-placeholder="全部" id="forumId"
									name="forumId" data-rel="chosen">
									<option value="0">全部</option>

								</select> <input type="hidden" name="pageNum" id="pageNum"
									value="${searchForm.pageNum }">

							</div>
							<div class="in-line">
								<label>上传时间：</label> <input class=" datepicker"
									name="startTime" id="date1" type="text" value="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至：
								<input class="input-large datepicker" name="endTime" id="date2"
									type="text" value="">
							</div>
							<div class="in-line">
								<label>文件名：</label> <input type="text" name="fileName"
									id="fileName" value="${searchForm.fileName }"
									class="input-large search-query"> <label>上传者：</label> <input
									type="text" name="username" id="username"
									value="${searchForm.username }"
									class="input-large search-query">

								<button type="button" id="searchBtn"
									class="btn btn-success">&nbsp;&nbsp;搜索&nbsp;&nbsp;</button>
								
									
									<input type="hidden" name="pageNum" id="pageNum"
								value="${searchForm.pageNum }"> <input type="hidden"
								name="infoId" id="infoId" value="${searchForm.infoId }">
							</div>
							

						</form>

					</div>
					<table id="userInfo" class="table table-striped table-bordered ">
						<thead>
							<tr>
								<th>序号</th>
								<th>小组名称</th>
								<th>文件名</th>
								<th>文件大小</th>
								<th>上传时间</th>
								<th>上传成员</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="info" items="${pageModel.result }"
								varStatus="status">
								<tr>
									<td>${status.index+1 }</td>
									<td>${info.groupName }</td>
									<td>${info.fileName }</td>
									<td>${info.size }</td>
									<td>${info.attachmentTime }</td>
									<td>${info.username }</td>
									<td>&nbsp;&nbsp; <a
										href="javascript:del('${info.attachmentId }')"><i
											class="icon-minus"></i></a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>

					<div id="mypager" class="mypager"></div>
				</div>
			</div>
		</div>
		<!--/fluid-row-->

	</div>
	<!--/.fluid-container-->

	<jsp:include page="../frame/scripts.jsp"></jsp:include>
	<script type="text/javascript">
		var pageNum = "${pageModel.pageNum}";
		var totalPage = "${pageModel.totalPage}";
		var numPerPage = "${pageModel.numPerPage}";

		$(document).ready(function() {

			$("#newBtn").click(function() {
				//跳转至新增页面
				window.location.href = '<c:url value="/admin/study/addAttachment" />';
			})
			
			$('.datepicker').datepicker('option', 'dateFormat', 'yy-mm-dd'); 
		
			$( "#date1" ).datepicker( "setDate", "${searchForm.startTime}" );
			$( "#date2" ).datepicker( "setDate", "${searchForm.endTime}" );
			
			$('#mypager').bootstrapPaginator({
				currentPage:pageNum,
				totalPages:totalPage,
				numberOfPages:numPerPage,
				onPageClicked:function(event, originalEvent, type,page){
					$("input[name='pageNum']").val(page);
					$("#searchForm").submit();
				}
			});
			
			
			$('#searchBtn').click(function(){
				$("#searchForm").submit();
			})
			
		//初始化院系专业
		$.ajax({
			url:'<c:url value="/admin/study/faculty/tree" />',
			dataType:'json',
			success:function(data){
				//搜索表单初始化版块下拉框
				createTree(data,"sorts");
				//设置选中
				$("#sorts_0").val("${searchForm.sortId}");
				$("#sorts_0").trigger("change");
				
				//增加下拉框样式
				//$('[data-rel="chosen"],[rel="chosen"]').chosen();
			}
		})
		
		$("#sorts_0").change(function(){
			$("#forumId").html("<option value='0'>全部</option>");
			var sortId = $(this).val();
			$.ajax({
				url:'<c:url value="/admin/study/group/list" />',
				dataType:'json',
				data:{sortId:sortId},
				success:function(data){
					$.each(data,function(i,item){
						$("#forumId").append("<option value='"+item.forumId+"'>"+item.name+"</option>");	
					})
					//初始化数据
					$("#forumId").val("${searchForm.forumId}");
				}
			})
		})
						
		})


		function del(infoId) {
			if (confirm("确定要删除吗？")) {
				$("input[name='infoId']").val(infoId);
				$("#searchForm").submit();
			}
		}
		
		function createTree(data,tagId){
			$.each(data,function(i,item){
				//生成节点
				createNode(item,tagId);
				if(item.children.length > 0){
					//生成子节点
					createTree(item.children,tagId);
				}
			})
		}

		function createNode(item,tagId){
			var $parent_select = $("#"+tagId+"_"+item.sortParent);
			var str = '';
			if(item.children.length > 0){
				str += '<optgroup id="'+tagId+'_'+item.sortId+'" label="'+item.sortName+'">';
				str += '</optgroup>';
			}else{
				str += '<option value='+item.sortId+'>'+item.sortName+'</option>';
			}
			$parent_select.append(str);
		}
	</script>
</body>
</html>
